package org.csu.mypetstore.controller;

import org.csu.mypetstore.aspect.LogAnnotation;
import org.csu.mypetstore.commonResponse.CommonResponse;
import org.csu.mypetstore.domin.Product;
import org.csu.mypetstore.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/products")
public class ProductController {
    @Autowired
    ProductService productService;
    //通过categoryid查询product信息
    @LogAnnotation(module="products",operation = "通过categoryid查询product信息")
    @GetMapping("/{category}")
    public CommonResponse<List<Product>> getProductListByCategory(@PathVariable("category") String categoryId){
        return productService.getProductListByCategory(categoryId);
    }

    //模糊查询product
    @LogAnnotation(module="products",operation = "通过name模糊查询product")
    @GetMapping("/search/{keywords}")
    CommonResponse<List<Product>> searchProductList(@PathVariable String keywords){
        return productService.searchProductList(keywords);
    }
}
